package com.ruoyi.web.controller.system;

import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.framework.util.ShiroUtils;
import com.ruoyi.system.domain.KrInfos;
import com.ruoyi.system.domain.OkrInfo;
import com.ruoyi.system.domain.SysUser;
import com.ruoyi.system.service.IOkrInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.io.PrintWriter;
import java.util.List;

/**
 * Created by Bruce on 2021/8/1 12:37
 **/
@Controller
@RequestMapping("/kanban")
public class OkrKanbanController {
    private String prefix = "system/kanban";

    @Autowired
    private IOkrInfoService okrInfoService;

    Long okr_id;

    @GetMapping("/{id}")
    public String main(@PathVariable("id") Long id,Model model){
        OkrInfo okrInfo = okrInfoService.selectOkrInfoById(id);
        okr_id = id;
        List<OkrInfo> list = okrInfoService.selectOkrInfoListByParentId(okrInfo);
        model.addAttribute("data", okrInfo);
        model.addAttribute("KRs", list);
        return prefix + "/kanban";
    }

    @RequestMapping("{id}/testJson")
    @ResponseBody
    public AjaxResult testJson(@PathVariable("id") Long okr_id, Long id, Integer status){
        this.okr_id = okr_id;
        OkrInfo okrInfo = okrInfoService.selectOkrInfoById(id);
        okrInfo.setWorkStatus(status);
        okrInfoService.updateOkrInfo(okrInfo);
        return AjaxResult.success();
    }

    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, Model model){
        OkrInfo okrInfo = okrInfoService.selectOkrInfoById(id);
        model.addAttribute("okrInfo", okrInfo);
        return prefix + "/edit";
    }



}
